package com.travelshare.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.travelshare.common.annotation.Log;
import com.travelshare.common.core.controller.BaseController;
import com.travelshare.common.core.domain.AjaxResult;
import com.travelshare.common.enums.BusinessType;
import com.travelshare.business.domain.DataCount;
import com.travelshare.business.service.IDataCountService;
import com.travelshare.common.utils.poi.ExcelUtil;
import com.travelshare.common.core.page.TableDataInfo;

/**
 * 用户点赞量统计Controller
 * 
 * @author travelshare
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/business/dataCount")
public class DataCountController extends BaseController {
	@Autowired
	private IDataCountService dataCountService;

	/**
	 * 查询用户点赞量统计列表
	 */
	@PreAuthorize("@ss.hasPermi('business:dataCount:list')")
	@GetMapping("/list")
	public TableDataInfo list(DataCount dataCount) {
		startPage();
		List<DataCount> list = dataCountService.selectDataCountList(dataCount);
		return getDataTable(list);
	}

	/**
	 * 导出用户点赞量统计列表
	 */
	@PreAuthorize("@ss.hasPermi('business:dataCount:export')")
	@Log(title = "用户点赞量统计", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, DataCount dataCount) {
		List<DataCount> list = dataCountService.selectDataCountList(dataCount);
		ExcelUtil<DataCount> util = new ExcelUtil<DataCount>(DataCount.class);
		util.exportExcel(response, list, "用户点赞量统计数据");
	}

	/**
	 * 获取用户点赞量统计详细信息
	 */
	@PreAuthorize("@ss.hasPermi('business:dataCount:query')")
	@GetMapping(value = "/{keyId}")
	public AjaxResult getInfo(@PathVariable("keyId") Long keyId) {
		return success(dataCountService.selectDataCountByKeyId(keyId));
	}

	/**
	 * 新增用户点赞量统计
	 */
	// @PreAuthorize("@ss.hasPermi('business:dataCount:add')")
	@Log(title = "用户点赞量统计", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody DataCount dataCount) {
		dataCount.setUserId(getUserId());
		return toAjax(dataCountService.insertDataCount(dataCount));
	}

	/**
	 * 修改用户点赞量统计
	 */
	@PreAuthorize("@ss.hasPermi('business:dataCount:edit')")
	@Log(title = "用户点赞量统计", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody DataCount dataCount) {
		return toAjax(dataCountService.updateDataCount(dataCount));
	}

	/**
	 * 删除用户点赞量统计
	 */
	@PreAuthorize("@ss.hasPermi('business:dataCount:remove')")
	@Log(title = "用户点赞量统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{keyIds}")
	public AjaxResult remove(@PathVariable Long[] keyIds) {
		return toAjax(dataCountService.deleteDataCountByKeyIds(keyIds));
	}

	@GetMapping("/deleteData")
	public AjaxResult deleteData(Long keyId, Integer keyType) {
		DataCount dataCount = new DataCount();
		dataCount.setUserId(getUserId());
		dataCount.setKeyId(keyId);
		dataCount.setKeyType(keyType);
		return toAjax(dataCountService.deleteDataCount(dataCount));
	}
}
